package com.lx.pc.restful.information;

import java.io.IOException;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.lx.pc.domain.vo.category.CategoryVo;
import com.lx.pc.domain.vo.information.InformationVo;
import com.lx.pc.domain.vo.sysarea.SysareaVo;
import com.lx.pc.restful.BaseController;
import com.lx.pc.service.category.ICategoryService;
import com.lx.pc.service.information.IInformationService;
import com.lx.pc.service.sysarea.ISysareaService;
import com.lx.pc.utils.OmsPage;

/**
 * 行情资讯
 * @author houzhong
 *
 */
@Controller
@RequestMapping(name = "information")
public class InformationController extends BaseController{
	
	/**
	 * 资讯
	 */
	@Resource(name = "informationService")
	private IInformationService informationService;
	
	/**
	 * 地区
	 */
	@Resource(name = "sysareaService")
	private ISysareaService sysareaService;
	
	/**
	 * 类目
	 */
	@Resource(name = "categoryService")
	private ICategoryService categoryService;
	
	
	/**
	 * 行情资讯首页
	 * @return
	 */
	@RequestMapping(value = "/toInformationList.do")
	public ModelAndView toInformationList() {
		ModelAndView mv = new ModelAndView("/information/information_list");
		
		//类目
		CategoryVo categoryVo = new CategoryVo();
		categoryVo.setType(1);
		categoryVo.setActive((short) 1);
		categoryVo.setStatus(1);
		OmsPage<CategoryVo> listVo = categoryService.findByCategory(categoryVo,1,5);
		
		//查询地区
		SysareaVo sysarea = new SysareaVo();
		sysarea.setParentCode("0");
	    List<SysareaVo> sysareaList = sysareaService.findBySysareaList(sysarea);
	    
	    mv.addObject("sysarea",sysareaList);
	    mv.addObject("categoryVo", listVo.getResult());
		return mv;
	}
	
	/**
	 * 热点资讯 列表
	 * @param v
	 * @param page
	 * @param size
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/informationList.do")
	@ResponseBody
    public  String informationList(InformationVo v,Integer page,Integer size) throws IOException {
        Map<String,Object> result = new HashMap<String, Object>();
        OmsPage<InformationVo> pages = informationService.findByInformation(v, page, size);
        result.put("informationVo", pages);
        return JSON.toJSONString(result);
    }
	
	/**
	 * 详情
	 * @return
	 */
	@RequestMapping(value = "/toInformationDetails.do")
	public ModelAndView toInformationDetails(String id) {
		ModelAndView mv = new ModelAndView("/information/information_details");
		BigInteger bId = new BigInteger(id); 
		InformationVo information = informationService.findByInformationId(bId);
		mv.addObject("information",information);
		return mv;
	}
	

}
